﻿<phone:PhoneApplicationPage 
    x:Class="SamsungRemoteWP7.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:SamsungRemoteWP7"
    xmlns:ads="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"
    xmlns:AdDuplex="clr-namespace:AdDuplex;assembly=AdDuplex.AdControl.Silverlight"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    local:TiltEffect.IsTiltEnabled="True"
    Style="{StaticResource TransitionPageStyle}"
    shell:SystemTray.IsVisible="True" Unloaded="PhoneApplicationPage_Unloaded" BackKeyPress="PhoneApplicationPage_BackKeyPress">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <controls:Pivot Title="Unofficial Samsung Remote v{v}" Name="MainPivot" SelectionChanged="MainPivot_SelectionChanged">
            <controls:PivotItem Header="tv list" Width="480" Margin="0,0,0,0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <ListBox x:Name="TvListBox" Margin="0,0,-12,0" ItemsSource="{Binding TvItems}" Grid.Row="0">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Tap="TvListPanel_Tap">
                                    <Image Source="TV.png" Width="62" Height="62" VerticalAlignment="Top"/>
                                    <StackPanel Margin="0,0,0,17" Width="432" Height="78">
                                        <TextBlock Text="{Binding TvName}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                        <StackPanel Orientation="Horizontal" Margin="12,-6,12,0">
                                            <TextBlock Text="{Binding TvAddress}" TextWrapping="NoWrap" Margin="0,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                            <TextBlock Text=":" Margin="3,-2,3,0"/>
                                            <TextBlock Text="{Binding Port}" TextWrapping="NoWrap" Margin="0,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <ads:AdControl x:Name="MSAdControl"
                                   Grid.Row="1"
                                   Height="80" Width="480"
                                   VerticalAlignment="Top"
                                   HorizontalAlignment="Left"
                    />

                    <AdDuplex:AdControl x:Name="AdDuplexAdControl"
                                        Grid.Row="1"
                                        Height="80" Width="480"
                                        Visibility="Collapsed"
                                        AppId="6095"
                                        VerticalAlignment="Top"
                                        HorizontalAlignment="Left"
                    />
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem Header="numpad" Name="first">
                <Grid>
                    <Image HorizontalAlignment="Left" VerticalAlignment="Top"
                           Source="Images/rack.png"  Margin="0,70,0,0"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="46,22,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_01.png" MyKey="KEY_1"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="190,22,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_02.png" MyKey="KEY_2"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="327,22,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_03.png" MyKey="KEY_3"/>

                    <Image HorizontalAlignment="Left" VerticalAlignment="Top"
                           Source="Images/rack.png" Margin="0,220,0,0"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="46,172,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_04.png" MyKey="KEY_4"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="190,172,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_05.png" MyKey="KEY_5"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="327,172,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_06.png" MyKey="KEY_6"/>

                    <Image HorizontalAlignment="Center" VerticalAlignment="Top"
                           Source="Images/rack.png" Margin="0,370,0,0"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="46,317,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_07.png" MyKey="KEY_7"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="190,317,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_08.png" MyKey="KEY_8"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="327,317,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_09.png" MyKey="KEY_9"/>

                    <Image HorizontalAlignment="Center" VerticalAlignment="Top"
                           Source="Images/rack.png" Margin="0,520,0,0"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="46,470,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_minus.png" MyKey="KEY_11"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="190,470,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_00.png" MyKey="KEY_0"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="327,470,0,0" Width="90" Height="120"
                           ImageLocation="Images/keypad_ch.png" MyKey="KEY_PRECH"/>
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem Header="navigation">
                <Grid>
                    <!-- menu controls -->
                    <Image VerticalAlignment="Top" Margin="0,0,0,0" Source="Images/direction_bg.png" />
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Left" Width="164" Height="108"
                        ImageLocation="Images/direction_content.png" MyKey="KEY_CONTENTS"/>
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Center" Width="156" Height="108"
                        ImageLocation="Images/direction_menu.png" MyKey="KEY_MENU"/>
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Right" Width="164" Height="108"
                        ImageLocation="Images/direction_internet.png" MyKey="KEY_RSS"/>

                    <!-- tools/info/return/exit -->
                    <Rectangle Fill="#66000000" RadiusX="10" RadiusY="10" Width="450" Height="120" Margin="3,122,0,0"
                               VerticalAlignment="Top" HorizontalAlignment="Left"/>
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Left" Margin="6,122,0,0" Width="120" Height="120"
                        ImageLocation="Images/direction_tools.png" MyKey="KEY_TOOLS"/>
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Left" Margin="118,122,0,0" Width="120" Height="120"
                        ImageLocation="Images/direction_info.png" MyKey="KEY_INFO"/>
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Left" Margin="232,122,0,0" Width="120" Height="120"
                        ImageLocation="Images/direction_return.png" MyKey="KEY_RETURN"/>
                    <local:TvKeyControl VerticalAlignment="Top" HorizontalAlignment="Left" Margin="344,122,0,0" Width="120" Height="120"
                        ImageLocation="Images/direction_exit.png" MyKey="KEY_EXIT"/>

                    <!-- navigation controls -->
                    <Image HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,250,0,0" Width="449" Height="321"
                           Source="Images/nav_bg.png"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="147,352,0,0" Width="160" Height="114"
                        ImageLocation="Images/key_keyboard.png" MyKey="KEY_ENTER"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="147,466,0,0" Width="160" Height="120"
                        ImageLocation="Images/key_down.png" MyKey="KEY_DOWN"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="307,348,0,0" Width="154" Height="124"
                        ImageLocation="Images/key_right.png" MyKey="KEY_RIGHT"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-7,347,0,0" Width="154" Height="124"
                        ImageLocation="Images/key_left.png" MyKey="KEY_LEFT"/>
                    <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="147,232,0,0" Width="160" Height="120"
                        ImageLocation="Images/key_up.png" MyKey="KEY_UP"/>

                    <!-- misc controls -->
                    <local:TvKeyControl Margin="25,53,327,57" Width="103" Height="64"
                        ImageLocation="Images/qwerty_btn.png" MyKey="KEY_INVALID" OnKeyPressed="OnQwertyButtonPressed"/>
                    <local:TvKeyControl Margin="25,487,327,57" Width="103" Height="64"
                        ImageLocation="Images/source_btn.png" MyKey="KEY_SOURCE"/>
                    <local:TvKeyControl Margin="329,53,29,59" Width="103" Height="64"
                        ImageLocation="Images/3d_btn.png" MyKey="KEY_PANNEL_CHDOWN"/>
                    <local:TvKeyControl Margin="329,490,29,59" Width="98" Height="58"
                        ImageLocation="Images/power_btn.png" MyKey="KEY_POWEROFF" OnKeyPressed="OnPowerButtonPressed"/>

                    <!--                     <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="184,366,0,0" Width="84" Height="65" -->
<!--                         ImageLocation="Images/nav_down.png" MyKey="KEY_DOWN"/> -->
<!--                     <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="271,308,0,0" Width="113" Height="57" -->
<!--                         ImageLocation="Images/nav_right.png" MyKey="KEY_RIGHT"/> -->
<!--                     <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="72,308,0,0" Width="113" Height="57" -->
<!--                         ImageLocation="Images/nav_left.png" MyKey="KEY_LEFT"/> -->
<!--                     <local:TvKeyControl HorizontalAlignment="Left" VerticalAlignment="Top" Margin="184,243,0,0" Width="84" Height="65" -->
<!--                         ImageLocation="Images/nav_up.png" MyKey="KEY_UP"/> -->
<!--                     <local:TvKeyControl HorizontalAlignment="Left" Margin="173,300,0,0" VerticalAlignment="Top" Width="108" Height="75" -->
<!--                         ImageLocation="Images/nav_center.png" MyKey="KEY_ENTER"/> -->
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem Header="control">
                <Grid>
                    <!-- play/pause controls -->
                    <!-- row 1 -->
                    <Image HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,70,0,0"
                            Source="Images/rack.png"/>
                    <local:TvKeyControl Margin="27,10,305,487" Width="124" Height="110"
                            ImageLocation="Images/playcontrol_rew.png" MyKey="KEY_WHEEL_LEFT"/>
                    <local:TvKeyControl Margin="166,10,166,487" Width="124" Height="110"
                            ImageLocation="Images/playcontrol_pause.png" MyKey="KEY_PAUSE"/>
                    <local:TvKeyControl Margin="303,10,29,487" Width="124" Height="110"
                            ImageLocation="Images/playcontrol_ff.png" MyKey="KEY_WHEEL_RIGHT"/>
                    <!-- row 2 -->
                    <Image HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,190,0,0"
                            Source="Images/rack.png"/>
                    <local:TvKeyControl Margin="27,130,305,367" Height="110" Width="124"
                            ImageLocation="Images/playcontrol_rec.png" MyKey="KEY_REC"/>
                    <local:TvKeyControl Margin="166,130,166,367" Height="110" Width="124"
                            ImageLocation="Images/playcontrol_play.png" MyKey="KEY_PLAY"/>
                    <local:TvKeyControl Margin="303,130,29,367" Height="110" Width="124"
                            ImageLocation="Images/playcontrol_stop.png" MyKey="KEY_STOP"/>

                    <!-- volume controls -->
                    <Image Margin="74,251,282,130" Width="100" Height="226"
                            Source="Images/volch_btn_bg.png"/>
                    <local:TvKeyControl Margin="74,251,282,257" Width="100" Height="99"
                            ImageLocation="Images/volum_up.png" MyKey="KEY_VOLUP" AllowRepeats="True"/>
                    <Image Margin="74,347,282,226" Width="100" Height="34"
                            Source="Images/volum_icon.png"/>
                    <local:TvKeyControl Margin="74,378,282,130" Width="100" Height="99"
                            ImageLocation="Images/volum_down.png" MyKey="KEY_VOLDOWN" AllowRepeats="True"/>

                    <local:TvKeyControl Margin="178,334,174,209" Width="103" Height="64"
                            ImageLocation="Images/mute_btn.png" MyKey="KEY_MUTE"/>
                    
                    <!-- channel controls -->
                    <Image Margin="286,251,70,130" Width="100" Height="226"
                            Source="Images/volch_btn_bg.png"/>
                    <local:TvKeyControl Margin="286,251,70,257" Width="100" Height="99"
                            ImageLocation="Images/ch_up.png" MyKey="KEY_CHUP"/>
                    <Image Margin="286,347,70,226" Width="100" Height="34"
                            Source="Images/ch_icon.png"/>
                    <local:TvKeyControl Margin="286,378,70,130"  Width="100" Height="99"
                            ImageLocation="Images/ch_down.png" MyKey="KEY_CHDOWN"/>

                    <!-- color controls -->
                    <Image HorizontalAlignment="Center" Margin="0,506,-7,20" Width="450" Height="81"
                            Source="Images/colorkey_bg.png"/>
                    <local:TvKeyControl Margin="14,509,336,23" Width="106" Height="75"
                            ImageLocation="Images/color_btn01.png" MyKey="KEY_RED"/>
                    <local:TvKeyControl Margin="123,509,227,23" Width="106" Height="75"
                            ImageLocation="Images/color_btn02.png" MyKey="KEY_GREEN"/>
                    <local:TvKeyControl Margin="232,509,118,23" Width="106" Height="75"
                            ImageLocation="Images/color_btn03.png" MyKey="KEY_YELLOW"/>
                    <local:TvKeyControl Margin="342,509,8,23" Width="106" Height="75"
                            ImageLocation="Images/color_btn04.png" MyKey="KEY_BLUE"/>
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem Header="misc" Margin="10,8,10,0">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <ListBox Grid.Column="0">
                        <ListBox.Items>
                            <local:TvKeyControl Text="Toggle Aspect Ratio" MyKey="KEY_ASPECT" Height="40"/>
                            <local:TvKeyControl Text="Energy Saving Mode" MyKey="KEY_ESAVING" Height="40"/>
                            <local:TvKeyControl Text="Sleep" MyKey="KEY_SLEEP" Height="40"/>
                            <local:TvKeyControl Text="PIP Toggle" MyKey="KEY_PIP_ONOFF" Height="40"/>
                            <local:TvKeyControl Text="PIP Size" MyKey="KEY_PIP_SIZE" Height="40"/>
                            <local:TvKeyControl Text="PIP Swap" MyKey="KEY_PIP_SWAP" Height="40"/>
                            <local:TvKeyControl Text="PIP Channel Up" MyKey="KEY_PIP_CHUP" Height="40"/>
                            <local:TvKeyControl Text="PIP Channel Down" MyKey="KEY_PIP_CHDOWN" Height="40"/>
                            <local:TvKeyControl Text="Closed Captioning" MyKey="KEY_CAPTION" Height="40"/>
                            <local:TvKeyControl Text="Game" MyKey="KEY_GAME" Height="40"/>
                            <local:TvKeyControl Text="Guide" MyKey="KEY_GUIDE" Height="40"/>
                            <local:TvKeyControl Text="Channel List" MyKey="KEY_CH_LIST" Height="40"/>
                            <local:TvKeyControl Text="Social" MyKey="KEY_TURBO" Height="40"/>
                            <local:TvKeyControl Text="Teletext Mix" MyKey="KEY_TTX_MIX" Height="40"/>
                            <local:TvKeyControl Text="Teletext Subface" MyKey="KEY_TTX_SUBFACE" Height="40"/>
                            <local:TvKeyControl Text="Multi-Track Sound" MyKey="KEY_MTS" Height="40"/>
                            <local:TvKeyControl Text="E-Manual" MyKey="KEY_TOPMENU" Height="40"/>
                            <local:TvKeyControl Text="W_Link" MyKey="KEY_W_LINK" Height="40"/>
                        </ListBox.Items>
                    </ListBox>

                    <ListBox Grid.Column="1">
                        <ListBox.Items>
                            <TextBlock Foreground="{StaticResource PhoneAccentBrush}" Text="Note: not all inputs work with all TVs" TextWrapping="Wrap"/>
                            <local:TvKeyControl Text="Input HDMI" MyKey="KEY_HDMI" Height="45"/>
                            <local:TvKeyControl Text="Input DVI" MyKey="KEY_DVI" Height="45"/>
                            <local:TvKeyControl Text="Input Component 1" MyKey="KEY_COMPONENT1" Height="45"/>
                            <local:TvKeyControl Text="Input Component 2" MyKey="KEY_COMPONENT2" Height="45"/>
                            <local:TvKeyControl Text="Input SVideo 1" MyKey="KEY_SVIDEO1" Height="45"/>
                            <local:TvKeyControl Text="Input SVideo 2" MyKey="KEY_SVIDEO2" Height="45"/>
                            <local:TvKeyControl Text="Input SVideo 3" MyKey="KEY_SVIDEO3" Height="45"/>
                            <local:TvKeyControl Text="Input AV 1" MyKey="KEY_AV1" Height="45"/>
                            <local:TvKeyControl Text="Input AV 2" MyKey="KEY_AV2" Height="45"/>
                            <local:TvKeyControl Text="Input AV 3" MyKey="KEY_AV3" Height="45"/>
                            <local:TvKeyControl Text="TV" MyKey="KEY_TV" Height="45"/>
                        </ListBox.Items>
                    </ListBox>
                </Grid>
            </controls:PivotItem>
        </controls:Pivot>

        <Grid Background="{StaticResource PhoneBackgroundBrush}" Opacity="0.85" Name="TextInputOverlay" Visibility="Collapsed">
            <StackPanel Margin="0,0,0,150" VerticalAlignment="Center">
                <TextBlock Text="Press Enter to submit the entered text," TextAlignment="Center"/>
                <TextBlock Text="press back to cancel." TextAlignment="Center"/>
                <TextBox Name="txtInput" Height="75" KeyUp="txtInput_KeyUp" LostFocus="txtInput_LostFocus" GotFocus="txtInput_GotFocus"
                         InputScope="Text"/>
            </StackPanel>
        </Grid>

        <Grid Background="{StaticResource PhoneBackgroundBrush}" Opacity="0" Name="TransparentOverlay" Visibility="Visible">
            <StackPanel VerticalAlignment="Center">
                <ProgressBar
                    IsIndeterminate="true"
                    x:Name="customIndeterminateProgressBar"
                    Style="{StaticResource CustomIndeterminateProgressBar}"/>
                <TextBlock Text="Loading..." Margin="30,0,30,0" FontSize="28" Name="progressText" TextWrapping="Wrap" TextAlignment="Center"/>
                <Button Content="Demo mode" Width="350" Click="btnDemoMode_Click" Name="btnDemoMode" Visibility="Collapsed"/>
            </StackPanel>
        </Grid>
    </Grid>
 
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="False" IsMenuEnabled="False">
            <shell:ApplicationBarIconButton IconUri="/Images/refresh.png" Text="refresh list" Click="RefreshTvList_Click"/>
            <shell:ApplicationBarIconButton IconUri="/Images/info.png" Text="app info" Click="ShowAppinfo_Click"/>
            <shell:ApplicationBarIconButton IconUri="/Images/gear32.png" Text="settings" Click="ShowSettings_Click"/>
<!--             <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/> -->
<!--             <shell:ApplicationBar.MenuItems> -->
<!--                 <shell:ApplicationBarMenuItem Text="MenuItem 1"/> -->
<!--                 <shell:ApplicationBarMenuItem Text="MenuItem 2"/> -->
<!--             </shell:ApplicationBar.MenuItems> -->
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>